package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.ProductDTO;
import net.wanho.po.Product;
import net.wanho.service.ProductService;
import net.wanho.mapper.ProductMapper;
import net.wanho.util.PageInfoUtil;
import net.wanho.vo.PageInfo;
import net.wanho.vo.ProductVo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.time.LocalDateTime;

/**
* @author Administrator
* @description 针对表【product(商品表)】的数据库操作Service实现
* @createDate 2024-10-18 16:14:23
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>
    implements ProductService{

    @Override
    public PageInfo<ProductVo> pageList(int pageNum, int pageSize, ProductDTO productDTO) {
        Page<ProductVo> page = new Page<>(pageNum, pageSize);
        QueryWrapper<ProductVo> wrapper = new QueryWrapper<>();
        wrapper.eq(!ObjectUtils.isEmpty(productDTO.getStoreId()), "s.store_id", productDTO.getStoreId());
        wrapper.like(!ObjectUtils.isEmpty(productDTO.getProductName()), "p.product_name", productDTO.getProductName());
        wrapper.eq(!ObjectUtils.isEmpty(productDTO.getBrandName()), "b.brand_name", productDTO.getBrandName());
        wrapper.eq(!ObjectUtils.isEmpty(productDTO.getTypeName()), "t.type_name", productDTO.getTypeName());
        wrapper.eq(!ObjectUtils.isEmpty(productDTO.getSupplyName()), "s2.supply_name", productDTO.getSupplyName());
        wrapper.eq(!ObjectUtils.isEmpty(productDTO.getPlaceName()), "p2.place_name", productDTO.getPlaceName());
        wrapper.eq(!ObjectUtils.isEmpty(productDTO.getUpDownState()), "p.up_down_state", productDTO.getUpDownState());
        if(productDTO.getIsOverDate() != null && productDTO.getIsOverDate()==0){
            wrapper.gt("p.supp_date", LocalDateTime.now());
        }else if(productDTO.getIsOverDate() != null && productDTO.getIsOverDate()==1){
            wrapper.lt("p.supp_date", LocalDateTime.now());
        }

        Page<ProductVo> p = this.baseMapper.selectPageList(page,wrapper);

        PageInfo<ProductVo> pageInfo = PageInfoUtil.convert(page);
        return pageInfo;
    }
}




